<?php
/**
 * Created by JetBrains PhpStorm.
 * User: thuann89
 * Date: 7/7/12
 * Time: 11:22 AM
 * To change this template use File | Settings | File Templates.
 */
class HomeArticleWidget extends CWidget
{
    public $title='';
    public $numOfItems = 2;
    public $category_id = '';
    public $emptyText='';
    public $contentLimited=500;

    public function getModel()
    {
        $criteria=new CDbCriteria();
        $criteria->with=array(
            'localeArticle' => array(
                'condition' => 'locale=:locale',
                'params' => array(':locale' => Yii::app()->language)
            ),
        );
        $criteria->compare('on_homepage',Article::IS_HOMEPAGE);
        $criteria->order='t.id DESC';
        $criteria->limit=2;
        $models = Article::model()->findAll($criteria);
        return $models;
    }


    public  function run()
    {
        parent::run();
        $this->render('home-article',array('models'=>$this->getModel()));
    }
}
